<?php

namespace ms\controllers;

use Yii;
use ms\models\LoginForm;
use common\models\ContactForm;


class SiteController extends \ms\components\Controller2015 {
	public function behaviors() {
		return [

		];
	}
	public function actions() {
		return [ 
			'error' => [ 
				'class' => 'yii\web\ErrorAction' 
			],
        ];
    }
    


    public function actionLogin()
    {

        if (!\Yii::$app->user->isGuest) {
        	
            return $this->goHome();
        }

        $model = new LoginForm();
        if ($model->load(Yii::$app->request->post()) && $model->login()) {
            return $this->goBack();
        } else {
//            print_r($model);die();
            return $this->render('login', [
                'model' => $model,
            ]);
        }
    }

    public function actionLogout()
    {
        Yii::$app->user->logout();
		//exit;
//        return $this->goHome();
        return $this->redirect(['site/admin']);
    }
    

    public function actionContact()
    {
        $model = new ContactForm();
        if ($model->load(Yii::$app->request->post() ) && $model->contact ( Yii::$app->params ['adminEmail'] )) {
            Yii::$app->session->setFlash ( 'contactFormSubmitted' );
            return $this->refresh ();
        } else {
            return $this->render ( 'contact', [ 
                    'model' => $model 
            ] );
        }
    }
    public function actionAbout() {
        return $this->render ( 'about' );
    }
    public function actionAdmin() {
            return $this->renderPartial ( 'admin' );
    }
    public function actionPic() {
            return $this->renderPartial ( 'pic_upload' );
    }

}
